package com.tiancheng.trade.settlement.exception;

import com.tiancheng.trade.settlement.exception.error.IErrorInfo;
import lombok.Getter;

/**
 * 基础异常类，所有自定义异常类都需要继承本类
 *
 * @author kellen
 * @date 2019-09-03
 */
@Getter
public class BaseException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误信息
     */
    protected IErrorInfo errorInfo;

    /**
     * 异常消息参数
     */
    protected Object[] args;

    public BaseException(IErrorInfo errorInfo) {
        super(errorInfo.getMessage());
        this.errorInfo = errorInfo;
    }

    public BaseException(int code, String msg) {
        super(msg);
        this.errorInfo = new IErrorInfo() {
            @Override
            public int getCode() {
                return code;
            }

            @Override
            public String getMessage() {
                return msg;
            }
        };
    }

    public BaseException(IErrorInfo errorInfo, Object[] args, String message) {
        super(message);
        this.errorInfo = errorInfo;
        this.args = args;
    }

    public BaseException(IErrorInfo errorInfo, Object[] args, String message, Throwable cause) {
        super(message, cause);
        this.errorInfo = errorInfo;
        this.args = args;
    }
}
